package ui;

import javax.swing.*;

import ui.handlers.MenuHandler;

import java.awt.*;

import java.rmi.RemoteException;
import javax.swing.border.EmptyBorder;

import core.MenuItemType;

import java.util.ArrayList;

public class SetDailySpecialScreen extends BaseScreen {

	private JFrame mainFrame;
	private JComboBox<MenuItemType> itemType_combobox;
	private JButton set_button;
	
	private ArrayList<Integer> menuItemIDs;
	private JTextField name_field;
	private JTextField price_field;
	private JTextField description_field;
	
	public ArrayList<Integer> getMenuItemIDs()
	{ return menuItemIDs; }
	
	public JButton getSetButton()
	{ return set_button; }
	
	public MenuItemType getSelectedMenuItemType()
	{ return (MenuItemType) itemType_combobox.getSelectedItem(); }
	
	public String getName()
	{return name_field.getText();}
	
	public String getPrice()
	{return price_field.getText();}
	
	public String getDescription()
	{return description_field.getText();}
	
	//public String getPriceText()
	//{ return price_tf.getText(); }
	
	public SetDailySpecialScreen()
	{
		mainFrame = new JFrame();
		mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		mainFrame.setTitle("Set Daily Special");
		mainFrame.setSize(450, 250);
		mainFrame.getContentPane().setLayout(new BorderLayout());
		
		try {
			menuItemIDs = store.getMenuItems();
		} catch (RemoteException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		doTitle();
		
		doButton();
		
		mainFrame.setVisible(true);
	}
	
	private void doTitle()
	{
		String title = "<html><font size = \"6\">Set Daily Special</font></html>";
		JLabel title_lbl = new JLabel(title);
		JPanel title_panel = new JPanel();
		title_panel.add(title_lbl);
		
		mainFrame.getContentPane().add(title_panel, BorderLayout.NORTH);
	}
	
	private void doButton()
	{
		set_button = new JButton("Set");
		set_button.addActionListener(new MenuHandler(this));
		
		JPanel SetSpecialPanel = new JPanel();
		mainFrame.getContentPane().add(SetSpecialPanel, BorderLayout.CENTER);
		SetSpecialPanel.setLayout(new BoxLayout(SetSpecialPanel, BoxLayout.X_AXIS));
		
		JPanel modify_panel = new JPanel();
		SetSpecialPanel.add(modify_panel);
		modify_panel.setBorder(new EmptyBorder(0, 0, 15, 0));
		modify_panel.setLayout(new GridLayout(3, 1));
		
		JLabel instruction_label = new JLabel("Add an item:");
		modify_panel.add(instruction_label);
		
		JPanel nameTypePrice_panel = new JPanel();
		modify_panel.add(nameTypePrice_panel);
		nameTypePrice_panel.setLayout(new GridLayout(1, 3));
		
		JPanel name_panel = new JPanel();
		nameTypePrice_panel.add(name_panel);
		name_panel.setLayout(new FlowLayout());
		
		JLabel name_label = new JLabel("Name:");
		name_panel.add(name_label);
		
		name_field = new JTextField(8);
		name_panel.add(name_field);
		
		JPanel type_panel = new JPanel();
		nameTypePrice_panel.add(type_panel);
		type_panel.setLayout(new FlowLayout());
		
		JLabel type_label = new JLabel("Type:");
		type_panel.add(type_label);
		try {
			itemType_combobox = new JComboBox<MenuItemType>(store.getMenuItemTypeValues());
			type_panel.add(itemType_combobox);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		JPanel price_panel = new JPanel();
		nameTypePrice_panel.add(price_panel);
		price_panel.setLayout(new FlowLayout());
						
		JLabel price_label = new JLabel("Price:");
		price_panel.add(price_label);
						
		price_field = new JTextField(8);
		price_panel.add(price_field);
						
		JPanel description_panel = new JPanel();
		modify_panel.add(description_panel);
		description_panel.setLayout(new BorderLayout());
						
		JLabel description_label = new JLabel("Description");
		description_panel.add(description_label, BorderLayout.WEST);
						
		description_field = new JTextField(6);
		description_field.setHorizontalAlignment(SwingConstants.LEFT);
		description_panel.add(description_field, BorderLayout.CENTER);
						
		JPanel buffer_panel = new JPanel();
		SetSpecialPanel.add(buffer_panel);
		buffer_panel.setLayout(new FlowLayout());
		
		JPanel button_panel = new JPanel();
		button_panel.setLayout(new GridLayout(1, 3));
		button_panel.add(new JPanel()); //empty panel
		button_panel.add(new JPanel()); //empty panel
		
		button_panel.add(set_button);
		
		button_panel.setBorder(new EmptyBorder(0, 0, 30, 15));
		
		mainFrame.getContentPane().add(button_panel, BorderLayout.SOUTH);
	}
	
	public JFrame getMainFrame() {
		return mainFrame;
	}
}